myApp.controller('addStyle', ['$scope', '$http', '$style', function($scope, $http, $style){
	$scope.styleName = "";
	$scope.styleDescription = "无";
	$scope.addStyle = function() {
		if($scope.styleName === "") {
			alert("请填写需要添加的款式名称！");
		}else {
			var styleData = {"style.name": $scope.styleName, "style.description": $scope.styleDescription};

			var postCfg = {
				headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
				transformRequest: function (data) {
					return $.param(data);
				}
			};

			$http.post('addStyle', styleData, postCfg).then(function successCallback(response) {
				alert("已添加成功！");
				$scope.styleName = "";
				$scope.styleDescription = "无";

				var promise = $style.loadAllStyle();
				promise.then(function(data) {
					$style.allStyle = data;
				}, function(n) {
					$style.allStyle = [{"name": "数据加载出错！"}];
				});
				console.log("ok：" + response);
			}, function errorCallback(response) {
				console.log("fail：" + response);
			});
		}
	};
}]);

myApp.controller('deleteStyle', ['$scope', '$http', '$style', function($scope, $http, $style){
	
	$scope.styleId = "";
	$scope.deleteStyle = function() {
		if ($scope.styleId === "" || $scope.styleId === null) {
			alert("请选择需要删除的款式！");
		}else {
			var styleData = {"style.styleId": $scope.styleId};

			var postCfg = {
				headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
				transformRequest: function (data) {
					return $.param(data);
				}
			};

			$http.post('deleteStyle', styleData, postCfg).then(function successCallback(response) {
				alert("已删除成功！");
				$scope.styleId = "";

				var promise = $style.loadAllStyle();
				promise.then(function(data) {
					$style.allStyle = data;
				}, function(n) {
					$style.allStyle = [{"name": "数据加载出错！"}];
				});
				console.log("ok：" + response);
			}, function errorCallback(response) {
				console.log("fail：" + response);
			});
		}
		
	};
}]);

myApp.controller('modifyStyle', ['$scope', '$http', '$style', function($scope, $http, $style){
	
	$scope.styleId = "";
	$scope.styleName = "";
	$scope.styleDescription = "无";
	$scope.modifyStyle = function() {
		if($scope.styleId === "" || $scope.styleId === null) {
			alert("请选择需要修改的款式！");
		}else if ($scope.styleName === "") {
			alert("请填写款式名称！");
		}else {
			var styleData = {"style.styleId": $scope.styleId, "style.name": $scope.styleName, "style.description": $scope.styleDescription};
			var postCfg = {
				headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
				transformRequest: function (data) {
					return $.param(data);
				}
			};

			$http.post('modifyStyle', styleData, postCfg).then(function successCallback(response) {
				alert("已修改成功！");
				$scope.styleId = "";
				$scope.styleName = "";
				$scope.styleDescription = "无";

				var promise = $style.loadAllStyle();
				promise.then(function(data) {
					$style.allStyle = data;
				}, function(n) {
					$style.allStyle = [{"name": "数据加载出错！"}];
				});
				console.log("ok：" + response);
			}, function errorCallback(response) {
				console.log("fail：" + response);
			});
		}
		
	};
}]);